package kr.saeildamil.androidhosoo.ch06;

import kr.saeildamil.androidstudy.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.Toast;

public class SetParameterEx extends Activity {
	Button mLeft;
	Button mRight;

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.setparameter);

		mLeft = (Button) findViewById(R.id.setparameter_btn1);
		mRight = (Button) findViewById(R.id.setparameter_btn2);

		mLeft.setOnClickListener(listener);
		mRight.setOnClickListener(listener);
	}

	View.OnClickListener listener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			if (v.getId() == R.id.setparameter_btn1) {
				setParam(1, 3);
			} else {
				setParam(3, 1);
			}
		}
	};

	protected void setParam(int left, int right) {
		LinearLayout.LayoutParams lparam = (LayoutParams) mLeft
				.getLayoutParams();
		LinearLayout.LayoutParams rparam = (LayoutParams) mRight
				.getLayoutParams();

		String str = "Left Button Weight : " + lparam.weight
				+ "\nRight Button Weight : " + rparam.weight;
		Toast.makeText(this, str, Toast.LENGTH_LONG).show();

		lparam.weight = left;
		rparam.weight = right;

		mLeft.setLayoutParams(lparam);
		mRight.setLayoutParams(rparam);

		str = "Left Button Weight : " + lparam.weight
				+ "\nRight Button Weight : " + rparam.weight;
		Toast.makeText(this, str, Toast.LENGTH_LONG).show();
	}
}
